<?php
include './head.php';

//提交评论
if($_POST['wid']&&$_POST['txt']){
    $pl=array();
    $pl['wid']=$_POST['wid'];
    $pl['txt']=$_POST['txt'];
    $pl['mid']=$_SESSION['home']['id'];
    $pl['user']=$_SESSION['home']['user'];
    $pl['time']=date('Y-m-d H:i:s',time());

    if(db_insert('bl_pl',$pl)){
        exit("<script>alert('评论成功');location.href='./new.php?id={$_POST['wid']}'</script>");
    }
}

//添加阅读量
db_query("update bl_wz set ydl=ydl+1 where id ='{$_GET['id']}'");

//接受id，查询文章数据
$id=$_GET['id'];

$sql="select w.*,c.pid,c.name from bl_wz as w join bl_class as c on w.cid = c.id where w.id =$id";
$wzarr=db_sel($sql); //查询这篇文章的所有数据和对应的分类数据

if($wzarr['pid']!=0){
    //我是二级
    //得到我的上级分类
    $class=db_sel("select * from bl_class where id = '{$wzarr['pid']}'");
}

/**上一篇和下一篇**/
$syp=db_sel("select id,title from bl_wz where cid={$wzarr['cid']} and id <{$wzarr['id']} order by id desc limit 1");
$xyp=db_sel("select id,title from bl_wz where cid={$wzarr['cid']} and id >{$wzarr['id']} order by id asc limit 1");

/**显示评论**/
$limit=2;
$page=$_GET['page']?$_GET['page']:1;
$offset=($page-1)*$limit;

//得到总页数
$cot=db_sel("select count(*) as co from bl_pl where wid = '$id'");
$cot=ceil($cot['co']/$limit);

$syy=$page-1>1?$page-1:1;
$xyy=$page+1<$cot?$page+1:$cot;

//查询数据
$sql="select * from bl_pl where wid=$id order by id desc limit $offset,$limit";
$plarr=db_sel($sql,2);

?>

<!--独立样式-->
<link href="../public/home/css/new.css" rel="stylesheet">

<article class="blogs">
    <h1 class="t_nav">
        <!--        显示文章对应的分类-->
        <?php if($wzarr['pid']==0){?>
            <a href="./newlist.php?cid=<?php echo $wzarr['cid']?>" class="n1"><?php echo $wzarr['name']?></a>
        <?php }else{?>
            <a href="./newlist.php?cid=<?php echo $class['id']?>" class="n1"><?php echo $class['name']?></a>
            <a href="./newlist.php?cid=<?php echo $wzarr['cid']?>" class="n2"><?php echo $wzarr['name']?></a>
        <?php }?>
    </h1>

    <div class="index_about">
        <!--        文章内容开始-->
        <h2 class="c_titile"><?php echo $wzarr['title']?></h2>
        <p class="box_c">
            <span class="d_time">发布时间：<?php echo date('Y-m-d',$wzarr['time'])?></span>
            <span>编辑：<?php echo $wzarr['user']?></span>

        </p>
        <?php if(empty($wzarr['ximg'])){}else{?>
        <p><img style="margin-top: 40px;" src="<?php echo $wzarr['ximg'];?>" alt="忆想"></p>
            <?php }?>
        <ul class="infos">
            <?php echo htmlspecialchars_decode($wzarr['txt'])?>
        </ul>

        <div class="ad"> </div>
        <div class="nextinfo">
            <p>上一篇：
                <?php if(empty($syp)){?>
                    无
                <?php }else{?>
                    <a href="./new.php?id=<?php echo $syp['id']?>"><?php echo $syp['title']?></a>
                <?php }?>
            </p>
            <p>下一篇：
                <?php if(empty($xyp)){?>
                    无
                <?php }else{?>
                    <a href="./new.php?id=<?php echo $xyp['id']?>"><?php echo $xyp['title']?></a>
                <?php }?>
            </p>
        </div>
        <!--        <div class="otherlink">-->
        <!--            <h2>相关文章</h2>-->
        <!--            <ul>-->
        <!--                <li><a href="/news/s/2013-07-25/524.html" title="现在，我相信爱情！">现在，我相信爱情！</a></li>-->
        <!--                <li><a href="/newstalk/mood/2013-07-24/518.html" title="我希望我的爱情是这样的">我希望我的爱情是这样的</a></li>-->
        <!--                <li><a href="/newstalk/mood/2013-07-02/335.html" title="有种情谊，不是爱情，也算不得友情">有种情谊，不是爱情，也算不得友情</a></li>-->
        <!--                <li><a href="/newstalk/mood/2013-07-01/329.html" title="世上最美好的爱情">世上最美好的爱情</a></li>-->
        <!--                <li><a href="/news/read/2013-06-11/213.html" title="爱情没有永远，地老天荒也走不完">爱情没有永远，地老天荒也走不完</a></li>-->
        <!--                <li><a href="/news/s/2013-06-06/24.html" title="爱情的背叛者">爱情的背叛者</a></li>-->
        <!--            </ul>-->
        <!--        </div>-->
    </div>
    <aside class="right">
        <!-- Baidu Button BEGIN -->

        <script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=6574585" ></script>
        <script type="text/javascript" id="bdshell_js"></script>
        <script type="text/javascript">
            document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
        </script>
        <!-- Baidu Button END -->
        <div class="blank"></div>
        <div class="news">
            <h3>
                <p><span>填写评论</span></p>
            </h3>
            <!--            提交评论-->
            <form action="./new.php" method="post" onsubmit="return tj()" style="text-align: right">
                <input type="hidden" name="wid" value="<?php echo $_GET['id']?>">
                <textarea name="txt" style="width: 246px;height: 50px;"></textarea>
                <br/>
                <input type="submit" value="提交评论">
            </form>

            <h3>
                <p><span>最新评论</span></p>
            </h3>
            <div>
                <?php foreach($plarr as $v){?>
                    <div style="border: 1px solid #ccc;margin-top: 10px;overflow:auto;">
                        <span style="float: left"><?php echo $v['user']?></span>
                        <span style="float: right;"><?php echo $v['time']?></span>
                        <div style="clear: both;padding-top: 5px;">
                            <?php echo $v['txt']?>
                        </div>
                    </div>
                <?php }?>

                <div>
                    <a href="./new.php?id=<?php echo $_GET['id']?>&page=<?php echo $syy?>" style="float: left">上一页</a>
                    <a href="./new.php?id=<?php echo $_GET['id']?>&page=<?php echo $xyy?>" style="float: right;">下一页</a>
                </div>
            </div>
        </div>
        <div class="visitors">
        </div>
    </aside>
</article>
<footer>
    <p>Design by DanceSmile <a href="http://www.mycodes.net/" title="源码之家" target="_blank">源码之家</a> <a href="/">网站统计</a></p>
</footer>
<script src="../public/Home/js/silder.js"></script>
<script>
    //判断是否登录
    function tj(){
        var uid="<?php echo $_SESSION['home']['id']?>"; //用户名
        if(uid){
            return true;
        }else{
            //提示登录，并且表单不提交
            alert('请登录！');
            location.href='./login.php';
            return false;
        }
    }


</script>
</body>
</html>